﻿component implements="CFIDE.orm.IEventHandler" {

	public void function preDelete(any entity) {

	}

	public void function preInsert(any entity) {
		//only run if we have both audit cols
		if(structKeyExists(arguments.entity, "setCreated") && structKeyExists(arguments.entity, "setEdited")) {
			arguments.entity.setCreated(dateformat(now(),'yyyy-mm-dd'));
			arguments.entity.setEdited(dateformat(now(),'yyyy-mm-dd'));
		}

	}

	public void function preUpdate(any entity, struct oldData) {
		//only run if we have both audit cols
		if(structKeyExists(arguments.entity, "setCreated") && structKeyExists(arguments.entity, "setEdited")) {
			arguments.entity.setEdited( dateformat(now(),'yyyy-mm-dd'));
		}
	}

	public void function preLoad( any entity) {

	}

	public void function postDelete( any entity) {

	}

	public void function postLoad( any entity) {
		if(structKeyExists(arguments.entity, "setCreated") && structKeyExists(arguments.entity, "setEdited")) {
			arguments.entity.setCreated( dateformat( arguments.entity.getCreated()  ,'yyyy-mm-dd'));
			arguments.entity.setEdited( dateformat( arguments.entity.getEdited()  ,'yyyy-mm-dd'));
		}

		if(structKeyExists(arguments.entity, "setExpiry")){
			arguments.entity.setExpiry( dateformat( arguments.entity.getExpiry()  ,'yyyy-mm-dd'));
		}

		if(structKeyExists(arguments.entity, "setReaded")){
			arguments.entity.setReaded( dateformat( arguments.entity.getReaded()  ,'yyyy-mm-dd'));
		}

	}

	public void function postUpdate( any entity) {

	}

	public void function postInsert( any entity) {

	}

}